import type {
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage,
  ConsultOrderPreParams,
  PartialConsult
} from '@/types/consult'
import type { ConsultOrderPreData } from '@/types/consult'
import type {
  DoctorPage,
  FollowType,
  Image,
  KnowledgePage,
  KnowledgeParams,
  PageParams,
  TopDep
} from '@/types/consult'
import type { Patient } from '@/types/user'
import { request } from '@/utils/request'

//获取文章列表页
//根据类型获取tag数据
const getKnowledgePage = (params: KnowledgeParams) =>
  request<KnowledgePage>('patient/home/knowledge', 'get', params)

//获取关注医生列表
const getDoctorPage = (params: PageParams) =>
  request<DoctorPage>('home/page/doc', 'get', params)

//关注
const followOrUnfollow = (id: string, type: FollowType = 'doc') =>
  request('like', 'post', { id, type })

//获取所有科室
const getAllDep = () => request<TopDep[]>('dep/all', 'get')

//上传图片
const uploadPicture = (file: File) => {
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('upload', 'POST', fd)
}

//获取用户预支付信息
const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('patient/consult/order/pre', 'get', params)

//获取用户详情
const getPatientInfo = (id: string) => request<Patient>(`patient/info/${id}`)

//获取订单信息
const getPatientOrder = (consult: PartialConsult) =>
  request<{ id: string }>('patient/consult/order', 'post', consult)

//支付
const getConsultOrderPayUrl = (params: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('patient/consult/pay', 'post', params)

//获取订单详情
const getconsultOrderItem = (orderId: string) =>
  request<ConsultOrderItem>('patient/consult/order/detail', 'get', { orderId })

//获取电子处方
const getPrescriptionPic = (id: string) =>
  request<{ url: string }>(`patient/consult/prescription/${id}`)

//提交评价
const evaluateConsultorder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) =>
  request<{
    id: string
  }>('patient/order/evaluate', 'POST', data)

//获取订单列表
const getConsultOrderList = (params: ConsultOrderListParams) =>
  request<ConsultOrderPage>('patient/consult/order/list', 'get', params)

//取消订单
const cancleOrder = (id: string) => request(`patient/order/cancel/${id}`, 'put')

//删除订单
const deleteOrder = (id: string) =>
  request(`patient/order/${id}`, 'delete', { id })
export {
  getKnowledgePage,
  getDoctorPage,
  followOrUnfollow,
  getAllDep,
  uploadPicture,
  getConsultOrderPre,
  getPatientInfo,
  getPatientOrder,
  getConsultOrderPayUrl,
  getconsultOrderItem,
  getPrescriptionPic,
  evaluateConsultorder,
  getConsultOrderList,
  cancleOrder,
  deleteOrder
}
